<?php

/**
 * Settings - Privacy
 * 
 * @project : Loobica
 * @author  : Dino
 * @date    : 27 Mar 2014
 * 
 */
if (!defined('BASEPATH'))
  exit('No direct script access allowed');

class Privacy extends LB_Auth_Controller {

  /**
   * Current User Privacy Settings
   * 
   */
  public function index() {

    // Init vars
    $status = false;
    $form_error = array('type' => null, 'message' => null);
    $flags = array(1, 2, 3);
    
    // Request Type
    if ($this->is_post()) {

      // Getting Inputs
      $user_email_privacy = (int) $this->input->post('email_privacy', true);
      $user_phone_privacy = (int) $this->input->post('phone_privacy', true);
      $user_social_privacy = (int) $this->input->post('social_privacy', true);

      // Cleaning Inputs
      $user_email_privacy = (in_array($user_email_privacy, $flags)) ? $user_email_privacy : 1;
      $user_phone_privacy = (in_array($user_phone_privacy, $flags)) ? $user_phone_privacy : 1;
      $user_social_privacy = (in_array($user_social_privacy, $flags)) ? $user_social_privacy : 1;

      // Inputs checking
      if (!empty($user_email_privacy) && !empty($user_phone_privacy) && !empty($user_social_privacy)) {

        // Reset fields
        $status = true;

        // Update user
        $user_set = array();
        $user_set['user_email_privacy'] = $user_email_privacy;
        $user_set['user_phone_privacy'] = $user_phone_privacy;
        $user_set['user_social_privacy'] = $user_social_privacy;
        $this->user_model->set_user($user_set, $this->signed_user['user_id']);
      }
    }

    // Getting user data
    $user_data = $this->user_model->get_user_id($this->signed_user['user_id'], 1, true);

    // Preparing view data
    $view_data = array();
    $view_data['title'] = 'Settings - Privacy';
    $view_data['status'] = $status;
    $view_data['form_error'] = $form_error;
    $view_data['user_data'] = $user_data;

    // Loading view
    $this->load_view('settings/privacy', $view_data);
    return;
  }

}

?>